package com.bootdo.xiao.suggest;

import java.util.Formatter;

/**
 * @Auther: liuj
 * @Date: 2019/5/27 15:57
 * @Description:建议7：警惕自增陷阱
 */
public class Suggest7 {
    public static void main(String[] args){
        int count = 0;
        int count2 = 0;
        /**
         * java处理循环时count2的步骤
         * 1、JVM把count2的值拷贝到临时变量区
         * 2、count2的值加1，此处为 1
         * 3、将临时变量区的值返回，注意值为0
         * 4、返回值 0赋值给count2，此时count2重置为0
         */
        for(int i=0; i<9; i++){
            count++;
            //
            count2 = count2++;
        }

        System.out.println("count = " + count);
        System.out.println("count2 = " + count2);
    }
}
